package com.isunland.managesystem.ui;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.DialogFragment;
import com.isunland.managesystem.R;
import com.isunland.managesystem.entity.CurrentUser;
import com.isunland.managesystem.entity.CustomerDialog;

public class ChooseTypeDialogFragment extends DialogFragment {
  protected static final String EXTRA_VALUE =
      "com.isunland.palmstudysystem.ui.ChooseTypeDialogFragment.extra_value";
  private int[] choiceIds = new int[] { R.string.out_storage, R.string.in_storage };
  private String[] choiceStrings = new String[choiceIds.length];
  private CurrentUser mUser;
  private String dataStatus = "";
  private String dataStatusId = "";

  @Override public void onCreate(Bundle savedInstanceState) {
    mUser = CurrentUser.newInstance(getActivity());
    super.onCreate(savedInstanceState);
  }

  @Override public Dialog onCreateDialog(Bundle savedInstanceState) {
    return new AlertDialog.Builder(getActivity()).setSingleChoiceItems(getChoiceName(), 0,
        new OnClickListener() {

          @Override public void onClick(DialogInterface arg0, int arg1) {
            //点击dialog后跳转

            Intent i = new Intent();
            switch (arg1) {
              //出库
              case 0:
                dataStatus = "出库";
                dataStatusId = "01";

                break;
              //入库
              case 1:
                dataStatus = "入库";
                dataStatusId = "02";

                break;

              default:
                break;
            }
            CustomerDialog systemDialog = new CustomerDialog(dataStatus, dataStatusId);

            Intent intent = new Intent();
            intent.putExtra(EXTRA_VALUE, systemDialog);
            if (getTargetFragment() == null) return;
            getTargetFragment().onActivityResult(getTargetRequestCode(), Activity.RESULT_OK,
                intent);
            arg0.dismiss();
          }
        }).create();
  }

  private String[] getChoiceName() {
    for (int i = 0; i < choiceIds.length; i++) {

      choiceStrings[i] = getResources().getString(choiceIds[i]);
    }

    return choiceStrings;
  }
}
